<template>
	<view class="content">
		<!-- <image class="logo" src="/static/logo.png"></image> -->
		<view class="uni-margin-wrap">
			<swiper class="swiper" circular :indicator-dots="banner.indicatorDots" :autoplay="banner.autoplay" :interval="banner.interval"
				:duration="banner.duration">
				<swiper-item v-for="item in banner.list">
					<view class="swiper-item uni-bg-red">
						<image style="width: 100%; height: 100%; background-color: #eeeeee;" :src="item.image"
						                        ></image>
					</view>
				</swiper-item>
			</swiper>
			<view class="nav">
				<view class="nav_item" v-for="nav in navs" @click="clickNavigator(nav.path)">
					<image class="nav_image" :src="nav.image"></image>
					<text class="nav_text">{{nav.name}}</text>
				</view>
			</view>
			<!-- 推荐商品 -->
			<view class="hot_sku">
				<view class="hot_sku_head">推荐商品</view>
				<view class="hot_sku_list">
					<view class="sku" v-for="sku in hotSkus" @click="clickSku(sku)">
						<image class="sku_image" :src="sku.image"></image>
						<view class="sku_price">
							<text>￥{{sku.price}}</text>
							<text>￥{{sku.origanlPrice}}</text>
						</view>
						<view class="sku_name">{{sku.name}}</view>
					</view>
				</view>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				banner:{}, //轮播图
				navs:{} ,// 导航栏
				hotSkus:{}, // 推荐商品
			}
		},
		onLoad() {
			console.log('--onload--start')
			this.fetchBanners()
			console.log('--end--start')
		},
		methods: {
			clickSku(sku) {
				uni.navigateTo({
					url:"/pages/sku/sku?id="+sku.id
				})
			},
			fetchBanners() {
				uni.request({
				  url: '/pages/index/index.json', // 你的JSON文件地址
				  method: 'GET',
				  success: (res) => {
				    if (res.statusCode === 200) {
				      // 请求成功，处理数据
					  console.log("banner", res.data);
					  this.banner = res.data.banner
					  this.navs = res.data.nav.list
					  this.hotSkus = res.data.hotSku.list
				    } else {
				      // 请求失败处理
				      console.error('请求失败1', res.statusCode);
				    }
				  },
				  fail: (err) => {
				    // 请求发生错误处理
				    console.error('请求出错2:', err);
				  }
				});
			},
			clickNavigator(url) {
				console.log(url);
				uni.navigateTo({
					url
				})
			},
			changeIndicatorDots(e) {
				this.indicatorDots = !this.indicatorDots
			},
			changeAutoplay(e) {
				this.autoplay = !this.autoplay
			},
			intervalChange(e) {
				this.interval = e.target.value
			},
			durationChange(e) {
				this.duration = e.target.value
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
	}
	.swiper {
		height: 300rpx;
	}
	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}
	.swiper-list {
		margin-top: 40rpx;
		margin-bottom: 0;
	}
	.uni-common-mt {
		margin-top: 60rpx;
		position: relative;
	}
	.info {
		position: absolute;
		right: 20rpx;
	}
	.uni-padding-wrap {
		width: 550rpx;
		padding: 0 100rpx;
	}
	
	.nav {
		display: flex;
	}
	.nav_item {
		width:25%;
		text-align: center;
		display:block;
	}
	.nav_image {
		width:120rpx;
		height:120rpx;
		border-radius: 60rpx;
		background: #e2211c;
		margin: 10px auto;
		display:block;
	}
	.nav_text {
		font-size:30rpx;
	}
	
	.hot_sku {
		background:#eee;
		margin-top:10px;
		overflow:hidden;
	}
	.hot_sku_head {
		background: #fff;
		height:50px;
		line-height:50px;
		color:#e2211c;
		text-align:center;
		letter-spacing:20px;
		margin:5px;
	}
	
	.hot_sku_list {
		display:flex;
		flex-wrap:wrap;
		justify-content: ‌‌flex-start;
	}
	
	.sku{
		background:#fff;
		width:355rpx;
		margin:5px;
		padding:5px;
		box-sizing: border-box;
	}
	
	.sku_image {
		width:80%;
		height:150px;
		display:block;
		margin:0 auto;
	}
	.sku_price {
		color:#e2211c;
		font-size:38rpx;
		margin:5px;
		text:nth-child(2) {
			color:#ccc;
			font-size:28rpx;
			margin-left:18px;
			text-decoration: line-through;
		}
	}
	.sku_name {
		font-size:38rpx;
		line-height: 50rpx;
		margin:5px;
	}
</style>
